package ferramentas;




import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author kako
 */
public class SingleConnection {
    private static String url = CFG.DB_LOCAL;
    private static String user = CFG.DB_USUARIO;
    private static String pass = CFG.DB_SENHA;
    private static Connection con = null;

    public static Connection getConnection(){
        //if(con == null){
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection(url,user,pass);
                return con;
            }
            catch (ClassNotFoundException e){
                System.out.println("Classe não encontrada!");
            }
            catch (SQLException e){
                System.out.println("Problemas com o BD - "+e);
            }
        //}
        return con;
    }
    
    public static Connection getConnectionSafe(){
        if(con == null){
            try {
                Class.forName("com.mysql.jdbc.Driver");
                con = DriverManager.getConnection(url,user,pass);
                return con;
            }
            catch (ClassNotFoundException e){
                System.out.println("Classe não encontrada!");
            }
            catch (SQLException e){
                System.out.println("Problemas com o BD - "+e);
            }
        }
        return con;
    }


}